/*
 * @Description: 
 * @Author: HKH
 * @Date: 2024-10-16 16:24:20
 * @LastEditors: HKH
 * @LastEditTime: 2024-10-17 15:51:52
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.Socket;
//客户端

public class Test { 
    public static void main(String[] args) throws UnknownHostException, IOException {
        //创建一个socket对象，准备链接服务区
        Socket socket =new Socket("127.0.0.1",8989);//地址，端口号
        InputStream is =socket.getInputStream();
        OutputStream os=socket.getOutputStream();
        //给服务器发送数据
        os.write("Hello world".getBytes());
        System.out.println("发送成功");
        //接收服务器返回的数据
        byte[] bytes=new byte[1024];
        int len =is.read(bytes);
        System.out.println("接收服务器端返回的数据"+new String(bytes,0,len));
        os.close();
        is.close();
        socket.close();
    }
}      